#Loading packages
library(jtools)
library(sandwich)
library(sjPlot)
library(sjlabelled)
library(sjmisc)
library(ggplot2)
library(car)
library(lmtest)
library(multiwayvcov)
library(plyr)
library(dummies)
library(gridExtra)
library(dplyr)
library(tidyr)
library(stargazer)
library(broom)
library(readxl)
library(tidyverse)
library(readstata13)
library(haven)
library(estimatr)
library(magrittr) 
library(texreg)
library(xtable)
library(gridExtra)
library(ggExtra)
library(cobalt)
library(MatchIt)
library(WeightIt)
library(Rmisc)
library(reshape2)
library(base)
library(dotwhisker)
library(broom)
library(dplyr)
library(readxl)
library(xlsx)
library(openxlsx)
library(readstata13)
library(cregg)
library(devtools)
library(ggbiplot)

# Please set your directory here

councilors <- read.dta13("full_sample_councilors.dta")
population <- read.dta13("councilors_population_represent.dta")
councilors <- merge(councilors,population, by="Q26_residence_2")

councilors$councilor<-1
councilors$councilor[is.na(councilors$responder_id)]<-0
summary(councilors$councilor)

number_participated <- aggregate(councilors$councilor, by=list(Q26_residence_2=councilors$Q26_residence_2), FUN=sum)
councilors <- merge(number_participated,councilors,  by="Q26_residence_2")

# Figure A.1: Councilor survey participation
councilors$participation_ratio <- councilors$x/councilors$councilors_num
summary(councilors$participation_ratio)
mean <- mean(councilors$participation_ratio)
hist(councilors$participation_ratio,  col="cadetblue", main = "Sample vs. Population of Councilors",
     xlab="Participation ratio")
abline(v = mean, col = "red", lwd = 2)

# Table A.1: Sample representativeness
participation2 <- lm_robust(participation_ratio ~ golden_d.y + nd.y + kinal.y + syriza.y + kke.y +
                              antarsya + 
                              female.y + camp, cluster=Q26_residence_2, data = councilors)
summary(participation2)

texreg(list(participation2), include.ci=FALSE)
